<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Spring Boot 运行时环境配置深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            position: relative;
            overflow: hidden;
        }
        
        .hero-gradient::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        pre {
            background: #1e1e1e;
            color: #d4d4d4;
            padding: 1.5rem;
            border-radius: 8px;
            overflow-x: auto;
            font-size: 14px;
            line-height: 1.6;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        code {
            background: #f3f4f6;
            padding: 0.2rem 0.4rem;
            border-radius: 4px;
            font-size: 0.9em;
            color: #6366f1;
        }
        
        pre code {
            background: none;
            padding: 0;
            color: #d4d4d4;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            box-shadow: 0 8px 16px rgba(102, 126, 234, 0.3);
        }
        
        .mermaid {
            text-align: center;
            margin: 2rem 0;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
            border-left: 4px solid #667eea;
            padding: 1.5rem;
            margin: 1.5rem 0;
            border-radius: 8px;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fadeInUp {
            animation: fadeInUp 0.8s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20 px-6 relative">
        <div class="max-w-6xl mx-auto relative z-10">
            <div class="text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-fadeInUp">
                    Spring Boot 运行时环境配置
                </h1>
                <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto animate-fadeInUp" style="animation-delay: 0.2s;">
                    深入探索 Spring Boot 应用的配置机制与环境管理
                </p>
                <div class="mt-8 flex justify-center space-x-4 animate-fadeInUp" style="animation-delay: 0.4s;">
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-cog mr-2"></i>自动配置
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-layer-group mr-2"></i>环境切换
                    </div>
                    <div class="bg-white bg-opacity-20 backdrop-filter backdrop-blur-lg rounded-full px-6 py-2">
                        <i class="fas fa-sync mr-2"></i>动态更新
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="max-w-6xl mx-auto px-6 py-12">
        <!-- Introduction Card -->
        <div class="content-card rounded-2xl p-8 mb-8 animate-fadeInUp">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>Spring Boot 应用的启动和运行过程中，运行时环境配置是至关重要的一部分。它不仅影响应用的初始化、配置加载和 Bean 创建，还直接关系到应用在不同环境下的运行表现。Spring Boot 的运行时环境配置非常灵活，通过自动配置、环境属性文件、条件化注解等机制，使得开发者能够根据不同的需求和环境进行定制化的配置。
            </p>
        </div>

        <!-- Architecture Overview -->
        <div class="content-card rounded-2xl p-8 mb-8 animate-fadeInUp">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap text-purple-600 mr-3"></i>配置架构概览
            </h2>
            <div class="mermaid">
                graph TB
                    A[SpringApplication] --> B[Environment]
                    B --> C[PropertySource]
                    B --> D[Profile]
                    C --> E[application.properties]
                    C --> F[application.yml]
                    C --> G[命令行参数]
                    D --> H[dev环境]
                    D --> I[prod环境]
                    A --> J[自动配置]
                    J --> K[@ConditionalOnClass]
                    J --> L[@ConditionalOnProperty]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style J fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Section 1 -->
        <div class="content-card rounded-2xl p-8 mb-8 animate-fadeInUp">
            <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                1. Spring Boot 的环境配置入口
            </h3>
            <p class="text-gray-700 mb-6 leading-relaxed indent-8">
                Spring Boot 的运行时环境配置主要依赖于 <code>SpringApplication</code> 类。<code>SpringApplication</code> 是 Spring Boot 应用的启动类，它负责创建应用上下文并初始化配置。
            </p>
            
            <div class="bg-gray-50 rounded-lg p-6 mb-6">
                <h4 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-code text-purple-600 mr-2"></i>
                    <code>SpringApplication</code> 类的 <code>run()</code> 方法
                </h4>
                <pre><code class="language-java">public ConfigurableApplicationContext run(String... args) {
    // 创建应用上下文
    ConfigurableApplicationContext context = createApplicationContext();
    
    // 初始化环境
    Environment environment = context.getEnvironment();
    configureEnvironment(environment);
    
    // 执行其他初始化任务
    prepareContext(context, environment, args);
    
    // 启动 Spring 应用
    context.refresh();
    return context;
}</code></pre>
            </div>
            
            <div class="grid md:grid-cols-3 gap-4">
                <div class="bg-purple-50 rounded-lg p-4">
                    <div class="feature-icon mb-3">
                        <i class="fas fa-box"></i>
                    </div>
                    <h5 class="font-semibold text-gray-800 mb-2">createApplicationContext()</h5>
                    <p class="text-sm text-gray-600">创建 ConfigurableApplicationContext，即应用的上下文</p>
                </div>
                <div class="bg-purple-50 rounded-lg p-4">
                    <div class="feature-icon mb-3">
                        <i class="fas fa-globe"></i>
                    </div>
                    <h5 class="font-semibold text-gray-800 mb-2">getEnvironment()</h5>
                    <p class="text-sm text-gray-600">获取 Environment，存储和管理所有环境属性</p>
                </div>
                <div class="bg-purple-50 rounded-lg p-4">
                    <div class="feature-icon mb-3">
                        <i class="fas fa-cogs"></i>
                    </div>
                    <h5 class="font-semibold text-gray-800 mb-2">configureEnvironment()</h5>
                    <p class="text-sm text-gray-600">配置 Environment，加载配置文件、设置系统属性</p>
                </div>
            </div>
        </div>

        <!-- Section 2 -->
        <div class="content-card rounded-2xl p-8 mb-8 animate-fadeInUp">
            <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                2. <code>Environment</code> 的作用
            </h3>
            <p class="text-gray-700 mb-6 leading-relaxed indent-8">
                <code>Environment</code> 是 Spring 中用于访问和管理环境属性的核心接口，它提供了对 <code>PropertySource</code> 的封装。在 Spring Boot 中，<code>Environment</code> 主要用于存取配置属性、区分不同的运行环境、以及处理系统属性和配置文件。
            </p>
            
            <div class="highlight-box">
                <h4 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-layer-group text-purple-600 mr-2"></i>
                    ConfigurableEnvironment 接口
                </h4>
                <pre><code class="language-java">public interface ConfigurableEnvironment extends Environment, ConfigurablePropertyResolver {
    void setActiveProfiles(String... profiles);
    void addActiveProfile(String profile);
    void setDefaultProfiles(String... profiles);
}</code></pre>
                <p class="text-gray-600 mt-4">
                    <code>ConfigurableEnvironment</code> 扩展了 <code>Environment</code> 和 <code>ConfigurablePropertyResolver</code> 接口，使得开发者能够动态设置活动配置文件。
                </p>
            </div>
        </div>

        <!-- Section 3 -->
        <div class="content-card rounded-2xl p-8 mb-8 animate-fadeInUp">
            <h3 class="section-title text-2xl font-bold mb-6 text-gray-800">
                3. Spring Boot 的自动配置机制
            </h3>
            <p class="text-gray-700 mb-6 leading-relaxed indent-8">
                Spring Boot 通过自动配置机制（<code>@EnableAutoConfiguration</code>）来简化运